package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.ClientPlan;
import cn.wolfcode.crm.domain.DictionariesItem;
import cn.wolfcode.crm.mapper.ClientPlanMapper;
import cn.wolfcode.crm.query.ClientPlanQuery;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IClientPlanService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ClientPlanServiceImpl implements IClientPlanService {
    @Autowired
    private ClientPlanMapper clientPlanMapper;




    public void saveOrUpdate(ClientPlan entity) {
        if (entity.getId() == null) {
            clientPlanMapper.insert(entity);
        } else {
            clientPlanMapper.updateByPrimaryKey(entity);
        }
    }

    public void delete(Long id) {
        clientPlanMapper.deleteByPrimaryKey(id);
    }

    public ClientPlan get(Long id) {
        return clientPlanMapper.selectByPrimaryKey(id);
    }

    public List<ClientPlan> listAll() {
        return clientPlanMapper.selectAll();
    }

    @Override
    public PageResult query(ClientPlanQuery qo) {
        int count = clientPlanMapper.queryCount(qo);
        if (count == 0) {
            return new PageResult(0, Collections.emptyList());
        }
        List<ClientPlan> clientPlans = clientPlanMapper.queryList(qo);
        PageResult pageResult = new PageResult(count, clientPlans);
        return pageResult;
    }




}
